package liaoxuefeng.demo;

import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;

/**
 * 服务端暴露到网络中 (一般暴露在内网主机)
 */
public class Server {
    public static void main(String[] args) throws RemoteException {
        System.out.println("create World clock remoter service ...");

        // 实例化
        WorldClock clock = new WorldClockService();
        // 将此服务转换为远程服务接口
        WorldClock skeleton = (WorldClock) UnicastRemoteObject.exportObject(clock, 0);
        // 将 RMI 服务注册到 1099 端口
        Registry registry = LocateRegistry.createRegistry(1099);
        // 注册此服务, 服务名
        registry.rebind("WorldClock", skeleton);

    }
}
